let id = 0
class Dep {
  constructor() {
    this.id = id++
    this.subs = []
  }
  //收集watcher
  depend() {
    //我希望watcher可以存放dep
    //双向记忆
    // this.subs.push(Dep.target)
    Dep.target.addDep(this)
  }
  addSub(watcher) {
    this.subs.push(watcher)
  }

  //更新watcher
  notify() {
    this.subs.forEach(watcher => watcher.update())
  }
}
Dep.target = null

//添加watcher
export function pushTarget(watcher) {
  Dep.target = watcher
}
//取消watcher
export function popTarget() {
  Dep.target = null
}

export default Dep
